package org.dubbo.consumer;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.remoting.TimeoutException;
import com.alibaba.dubbo.rpc.RpcException;
import lif.dubbo.EchoService;

/**
 * Hello world!
 *
 */
public class PureApi {

	@SuppressWarnings("rawtypes")
	public static void start() throws Exception {

		RegistryConfig registry = new RegistryConfig();
		registry.setAddress("127.0.0.1:2181");
		registry.setProtocol("zookeeper");

		ApplicationConfig applicationConfig = new ApplicationConfig();
		applicationConfig.setName("an");

		ReferenceConfig<EchoService> reference = new ReferenceConfig<EchoService>();
		reference.setRegistry(registry);
		reference.setInterface(EchoService.class);
		reference.setCheck(false);
		reference.setApplication(applicationConfig);
		reference.setTimeout(1000);
		//版本号要一样,要都没有配置
		reference.setVersion("1.0.0");
		EchoService xxxService = reference.get();
		try {
            System.out.println("sleep");
		    Thread.sleep(5*1000);
            System.out.println("go on ....");

			System.out.println("consumer " + xxxService.echo("lif")); // 显示调用结果

		}catch (RpcException e){
			System.out.println("error" +e.getCode() +"---" +e.getMessage());
			e.printStackTrace();
		}catch (Exception e){
			System.out.println(" error is =>" + (e instanceof  TimeoutException));
		    e.printStackTrace();

		}


	}

	public static void main(String[] args) throws Exception {
		start();
		System.exit(1);
	}

}
